#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>
char * left(char* p1 , size_t len,int x)
{
	x = x % len;
	char* p2 = p1 + len;
	int i = x-1;
	for (; i >= 0; i--)
	{
		*(p2 + i) = *(p1 + i);
	}
	*(p2 + x) = '\0';
	return p1 + x;
}
//int main()
//{
//	char arr[1000] = {0};
//	unsigned int x = 0;
//	while (scanf("%s %ud", arr,&x))
//	{
//		size_t len = strlen(arr);
//		printf(left(arr,len,x));
//	}
//	
//}
size_t my_strlen(char* arr)
{
	size_t op = 0;
	while (*arr != '\0')
	{
		op++;
		arr = arr + 1;
	}
	return op;
}
void wechs1(int* arr,int len)
{
	int* left = arr;
	int* right = arr + len - 1;
	while (left < right)
	{
		int tmp = 0;
		while (*left % 2 == 1&&left<right)
		{
			left=left + 1 ;
		}
		while (*right % 2 == 0&&left<right)
		{
			right= right -1;
		}
		tmp = *left;
		*left = *right;
		*right = tmp;

	}
}
//int main()
//{
//	int arr[] = {1,2,3,4,5,6,7,8,9};
//	int len = sizeof(arr) / sizeof(arr[0]);
//	wechs(arr, len);
//	for (int i = 0; i < len; i++)
//	{
//		printf("%d ", arr[i]);
//	}
//}

void left1(char* str, int x)
{
	x = x % strlen(str);
	char arrtmp[256] = { 0 };
	char* arr = arrtmp;
	strcpy(arr, str + x);
	strncat(arr, str, x);
	strcpy(str, arr);
}
void left2(char* str,int x)
{
	for (int i = 0; i < x; i++)
	{
		char tmp = *str;
		for (int j = 0; j <= x; j++)
		{
			str[j] = str[j + 1];
		}
		str[x + 1] = tmp;
	}
}
//int main()
//{
//	char str[] = "abdjasd";
//	left2(str, 2);
//	printf(str);
//}
//int main()
//{
//	int arr[] = { 12,35,478,79 };
//	for (int i = 0; i < sizeof(arr) / sizeof(arr[0]); i++)
//	{
//		printf("%d ", *(arr + i));
//	}
//	return 0;
//}
void my_qsort(int* p, int len)
{
	for (int i = 0; i < len - 1; i++)
	{
		int* arr = p;
		for (int j = 0; j < len - i - 1; j++)
		{
			int tmp = 0;
			if (arr[j] > arr[j+1])
			{
				tmp = arr[j];
				arr[j] = arr[j+1];
				arr[j+1] = tmp;
			}
		}
	}
}
//int main()
//{
//	int arr[] = { 8,5,4,6,3,2,9,1 };
//	my_qsort(arr, sizeof(arr) / sizeof(arr[0]));
//	for (int i = 0; i < sizeof(arr) / sizeof(arr[0]); i++)
//	{
//		printf("%d ", arr[i]);
//	}
//}
int wechs(char* arr1, char* arr2)
{
	char str[256] = { 0 };
	int op= 0;
	for (int i = 1; i < strlen(arr1); i++)
	{
		strcpy(str, arr1 + 1);
		strncat(str, arr1, 1);
		strcpy(arr1, str);
		if (strcmp(arr1, arr2) == 0)
			op = 1;
	}
	return op;
}
//int main()
//{
//	char arr[] = "abcde";
//	char str[] = "cdeba";
//	printf("%d ", wechs(arr, str));
//	return 0;
//}
int find_key(int(*arr)[3], int x, int y, int key)
{
	int i = 0;
	int j = y - 1;
	/*while (arr[i][j] < key && i <x-1)
	{
		i++;
	}
	while(arr[i][j] > key && j>=0) 
	{
		j--;
	}
	if (  arr[i][j] == key )
		return 1;
	return 0;*/
	while (i < x - 1 && j > 0)
	{
		if (arr[i][j] == key)
		{
			return 1;
		}
		else if (arr[i][j] > key)
		{
			i++;
		}
		else
			j--;
	}
	return 0;
}
//int main()
//{
//	int arr[4][2] = { 0,1,2,3,4,6,7,8 };
//	printf("%d ", find_key(arr, 4, 2, -1));
//}
//int main()
//{
//	char killer = 'a';
//	for (; killer <= 'd'; killer++)
//	{
//		if ((killer != 'a') + (killer == 'c' )+ (killer == 'd' )+ (killer != 'd') == 3)
//			printf("%c ", killer);
//	}
//}
void YangHui(int arr[][4], int x)
{
	for (int i = 0; i < x; i++)
	{
		for (int j = 0; j <= i; j++)
		{
			if (i == j)
				arr[i][j] = 1;
			else if (j == 0)
				arr[i][j] = 1;
			else
				arr[i][j] = arr[i - 1][j] + arr[i - 1][j - 1];
		}
	}
}
void print(int arr[][4], int x)
{
	for (int i = 0; i < x; i++)
	{
		for (int j = 0; j <= i; j++)
		{
			
			printf("%d ", arr[i][j]);
		}
		printf("\n");
	}
}
//int main()
//{
//	int arr[100][100] = { 0 };
//	YangHui(arr, 100);
//	print(arr, 100);
//	return 0;
//}

void swap(void* p1, void* p2, size_t sz) {
	for (size_t i = 0; i < sz; i++) {
		char tmp = ((char*)p1)[i];
		((char*)p1)[i] = ((char*)p2)[i];
		((char*)p2)[i] = tmp;
	}
}

void my_qsort(void* str, size_t num, size_t size, int (*p)(const void*, const void*)) 
{
	for (size_t i = 0; i < num - 1; i++) {
		for (size_t j = 0; j < num - 1 - i; j++) {
			if (p((char*)str + j * size, (char*)str + (j + 1) * size) > 0) {
				swap((char*)str + j * size, (char*)str + (j + 1) * size, size);
			}
		}
	}
}